package com.roy.wakeupes.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import toolgood.words.IllegalWordsSearch;
import toolgood.words.IllegalWordsSearchResult;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class WordService {

    @Autowired
    private IllegalWordsSearch wordsSearch;


    public boolean test(String content){
        // 校验评论中是否包含敏感词
        boolean res = wordsSearch.ContainsAny(content);

        System.out.println(res);
        if (res) {
            // 匹配到的所有敏感词组
            List<IllegalWordsSearchResult> results = wordsSearch.FindAll(content);
            List<String> keywords = results.stream().map(result -> result.Keyword).collect(Collectors.toList());
            // 不同过的原因
            String  reason = String.format("系统自动拦截，包含敏感词：%s", keywords);
            log.warn("此评论内容中包含敏感词: {}, content: {}", keywords, content);
        }

        return res;
    }

}
